package com.mikelouis.test.scala.proginscala.chapter16

/**
 * Created by yuazhu on 1/20/2015.
 */
object TypeDeductionAlgo {
  def main(args: Array[String]) {
    val abcde = List('a', 'b', 'c', 'd', 'e')
    println(MergeSort.msort((x: Char, y: Char) => x > y)(abcde))
    println(abcde sortWith (_ > _))

    // will throw compile error
    // Error:(12, 21) missing parameter type for expanded function ((x$3, x$4) => x$3.$greater(x$4))
    //    MergeSort.msort(_ > _)(abcde)
    //                      ^
//    MergeSort.msort(_ > _)(abcde)

    // 明确的把类型参数传递给msort
    MergeSort.msort[Char](_ > _)(abcde)

    // 重写msort方法以交换它的参数顺序
    def msortSwapped[T](xs: List[T])(less: (T, T) => Boolean): List[T] =
      MergeSort.msort(less)(xs)
    println(msortSwapped(abcde)(_ > _))
  }

}
